﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BattleThis.Core;

namespace BattleThis.Common
{
	/// <summary>
	/// Represents a User Selection.
	/// </summary>
	public class Selection
	{

		#region Variablen
		public readonly static Selection None =new Selection();
		#endregion

		#region Properties
		public Unit Unit { get; protected set; }
		public IEnumerable<Position> MoveRange { get; protected set; }
		public IEnumerable<Position> AttackRange { get; protected set; }
		#endregion

		#region Methoden

		/// <summary>
		/// Initializes a new instance of the <see cref="Selection"/> class.
		/// </summary>
		protected Selection()
		{
			this.Unit = Unit.Empty;
			this.MoveRange = Enumerable.Empty<Position>();
			this.AttackRange = Enumerable.Empty<Position>();
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Selection"/> class.
		/// </summary>
		/// <param name="selected">The selected.</param>
		/// <param name="moveRange">The move range.</param>
		/// <param name="attackRange">The attack range.</param>
		public Selection( Unit selected, IEnumerable<Position> moveRange, IEnumerable<Position> attackRange  )
		{
			if( selected == null )throw new ArgumentNullException( "selected" );
			if( moveRange == null )throw new ArgumentNullException( "moveRange" );
			if( attackRange == null )throw new ArgumentNullException( "attackRange" );

			this.Unit = selected;
			this.MoveRange = moveRange;
			this.AttackRange = attackRange;
		}

		/// <summary>
		/// Determines whether this instance is none.
		/// </summary>
		/// <returns>
		///   <c>true</c> if this instance is none; otherwise, <c>false</c>.
		/// </returns>
		public bool IsNone()
		{
			return this.Equals( None );
		}

		/// <summary>
		/// Determines whether [is in move range] [the specified field].
		/// </summary>
		/// <param name="field">The field.</param>
		/// <returns>
		///   <c>true</c> if [is in move range] [the specified field]; otherwise, <c>false</c>.
		/// </returns>
		public bool IsInMoveRange( Field field )
		{ 
			if( field == null )throw new ArgumentNullException( "field" );

			return this.MoveRange.Contains( field.Position );
		}

		/// <summary>
		/// Determines whether [is in attack range] [the specified field].
		/// </summary>
		/// <param name="field">The field.</param>
		/// <returns>
		///   <c>true</c> if [is in attack range] [the specified field]; otherwise, <c>false</c>.
		/// </returns>
		public bool IsInAttackRange( Field field )
		{
			if( field == null ) throw new ArgumentNullException( "field" );

			return this.AttackRange.Contains( field.Position );
		}

		#endregion
	}
}